<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px">
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="用户ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户昵称" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="用户昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户手机号" prop="userPhone">
        <el-input v-model="queryParams.userPhone" placeholder="用户手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="反馈类型" prop="feedType">
        <el-select v-model="queryParams.feedType" placeholder="反馈类型" clearable>
          <el-option v-for="dict in feedTypeList" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="orderheadList" style="width: 100%">
      <el-table-column label="用户ID" prop="userId">
      </el-table-column>
      <el-table-column label="用户昵称" prop="nickName">
      </el-table-column>
      <el-table-column label="用户手机号" prop="userPhone">
      </el-table-column>
      <el-table-column label="用户来源" prop="submitSource">
        <!-- 提交来源;0-小程序 1-iso 2-安卓  -->
        <template slot-scope="scope">
          <el-tag v-if="scope.row.submitSource=='0'" type="warning">小程序</el-tag>
          <el-tag v-else-if="scope.row.submitSource=='1'" type="danger">iOS</el-tag>
          <el-tag v-else-if="scope.row.submitSource=='2'" type="success">安卓</el-tag>
          <el-tag v-else type="info">''</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="反馈来源" prop="feedType">
        <!-- 反馈类型 1-功能问题 2-优化建议 3-其他  -->
        <template slot-scope="scope">
          <el-tag v-if="scope.row.feedType=='1'" type="warning">功能问题</el-tag>
          <el-tag v-else-if="scope.row.feedType=='2'" type="danger">优化建议</el-tag>
          <el-tag v-else-if="scope.row.feedType=='3'" type="success">其他</el-tag>
          <el-tag v-else type="info">''</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="详细内容" prop="content">
        <template slot-scope="scope">
          <div class="ellipsis">{{scope.row.content}}</div>
        </template>
      </el-table-column>
      <el-table-column label="图片" prop="picUrls">
        <template slot-scope="scope">
          <div v-if="scope.row.list.length>0" style="display: flex;">
            <div style="width: 100px;height: 100px;">
              <el-image style="width: 100px; height: 100px" :src="scope.row.list[0]" :preview-src-list="scope.row.list"
                fit="contain"></el-image>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime">
      </el-table-column>
      <el-table-column label="平台备注" prop="platformRemark">
        <template slot-scope="scope">
          <div class="ellipsis">{{scope.row.platformRemark}}</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="viewRemark(scope.row)">设置备注</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="用户ID" prop="userId">
          <el-input disabled v-model="form.userId" type="text" placeholder="用户ID" />
        </el-form-item>
        <el-form-item label="用户昵称" prop="nickName">
          <el-input disabled v-model="form.nickName" placeholder="用户昵称" />
        </el-form-item>
        <el-form-item label="用户手机号" prop="userPhone">
          <el-input disabled v-model="form.userPhone" placeholder="用户手机号" />
        </el-form-item>
        <el-form-item label="用户来源" prop="submitSource">
          <el-input disabled v-model="form.submitSource" placeholder="用户来源" />
        </el-form-item>
        <el-form-item label="反馈来源" prop="feedType">
          <el-input disabled v-model="form.feedType" placeholder="反馈来源" />
        </el-form-item>
        <el-form-item label="详细内容" prop="content">
          <el-input disabled type="textarea" maxlength="1000" rows="5" v-model="form.content" placeholder="详细内容" />
        </el-form-item>
        <el-form-item label="图片" prop="list">
          <div style="display: flex;flex-wrap: wrap;">
            <div v-for="(item,index) in oldKdfPicList" :key="index">
              <el-image style="width: 200px; height: 100px" :preview-src-list="oldKdfPicList" :src="item"
                fit="contain"></el-image>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-input disabled v-model="form.createTime" placeholder="创建时间" />
        </el-form-item>
        <el-form-item label="平台备注" prop="platformRemark">
          <el-input disabled type="textarea" maxlength="1000" rows="5" v-model="form.platformRemark" />
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="备注信息" :visible.sync="remarkVisible" @close="remarkClose" width="25%">
      <div>
        <div>平台备注</div>
        <div style="width: 100%;margin-top: 10px;margin-bottom: 10px;">
          <el-input style="width: 100%;" type="textarea" maxlength="400" v-model.trim="platName" placeholder="平台备注" />
        </div>
        <div style="text-align: center;">
          <el-button :disabled="platName ? false : true" type="primary" @click="remarkConfirm">确定</el-button>
          <el-button @click="remarkCancel">取消</el-button>
        </div>
      </div>
    </el-dialog>

  </div>
</template>
<script>
  import {
    feedbackList,
    mgmtRemark
  } from "@/api/store/feedback";

  export default {
    name: "Orderhead",
    dicts: ['con_value_behavior', ],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单表头表格数据
        orderheadList: [],
        // 弹出层标题
        title: "详细内容",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          nickName: null,
          keyword: null,
          userId: null,
          source: null,
          minNum: null,
          maxNum: null,
          startDate: null,
          endDate: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        dateRange: [],
        oldKdfPicList: [],
        feedTypeList: [{
            label: '功能问题',
            value: '1'
          },
          {
            label: '优化建议',
            value: '2'
          },
          {
            label: '其他',
            value: '3'
          }
        ],
        remarkVisible: false,
        platName: '',
        id:''
      };
    },


    created() {
      this.getList();
    },
    methods: {
      getStatus(res) {
        return res === '0' ?
          '待付款' :
          res === '5' ?
          '待发货' :
          res === '1' ?
          '待发货' :
          res === '6' ?
          '已发货' :
          res === '2' ?
          '已发货' :
          res === '3' ?
          '完成' :
          res === '4' ?
          '售后' :
          res === '7' ?
          '完成' :
          res === '8' ?
          '退款' :
          res === '9' ?
          '退货退款' :
          res === '10' ?
          '交易关闭' :
          '其他'
      },
      /** 查询订单表头列表 */
      getList() {
        let params = {
          // 用户昵称
          feedType: this.queryParams.feedType,
          // 用户id
          userId: this.queryParams.userId,
          // 入驻家乡关键词
          nickName: this.queryParams.nickName,
          // 贡献值行为
          userPhone: this.queryParams.userPhone,
          // 贡献值数区间
          submitSource: this.queryParams.submitSource,
          pageSize: this.queryParams.pageSize,
          pageNum: this.queryParams.pageNum
        }
        feedbackList(params).then(res => {
          if (res.code == '200') {
            this.orderheadList = res.rows
            this.orderheadList.map(v => {
              let result = v.picUrls ? v.picUrls.split(',') : []
              if (result.length > 0) {
                v.list = result
              } else {
                v.list = []
              }
            })
          }
          this.total = res.total
        });
      },

      handleView(row) {
        this.form = JSON.parse(JSON.stringify(row))
        this.oldKdfPicList = this.form.list
        this.open = true
      },

      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          orderSerial: null,
          userId: null,
          addressId: null,
          totalAmount: null,
          couponFlag: null,
          coupon: null,
          actualAmount: null,
          emsFlag: null,
          emsFreight: null,
          orderStatus: null,
          successFlag: null,
          paySerial: null,
          orderTime: null,
          payTime: null,
          payMethods: null,
          deliveryMethod: null,
          orderRemark: null,
          invoiceFlag: null,
          delFlag: null,
          crTime: null,
          upTime: null,
          headFeild1: null,
          headFeild2: null,
          headFeild3: null,
          headFeild4: null,
          headFeild5: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = []
        this.queryParams.maxNum = null
        this.queryParams.ruleId = null
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.orderSerial)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      remarkClose(){
        this.remarkVisible = false
      },
      viewRemark(row) {
        this.id = row.id
        this.remarkVisible = true
      },
      remarkConfirm() {
        if (this.platName) {
          let params = {
            "id": this.id,   //用户优惠券记录ID
            "platformRemark": this.platName  //平台备注
          }
          mgmtRemark(params).then(response => {
            this.$modal.msgSuccess("成功");
            this.open = false;
            this.getList();
          });
        }
        this.remarkVisible = false
      },

      remarkCancel() {
        this.remarkVisible = false
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.orderSerial != null) {
              updateOrderhead(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addOrderhead(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
    }
  };
</script>
<style scoped>
  .br /deep/ .el-descriptions__header {
    display: none !important;
  }

  .ec-input-range-divider {
    width: 10px;
    height: 2px;
    background-color: #333;
    margin: 0 auto;
  }

  .ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  /deep/ .setHeight .el-textarea.is-disabled .el-textarea__inner{
    height: 100% !important;
  }
</style>
